package com.lord.wand.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lord.wand.entity.User;
import com.lord.wand.service.IUserService;

@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	private IUserService userService;

	@RequestMapping("/list")
	@ResponseBody
	public ModelAndView list(User model) {
		ModelAndView modelAndView = new ModelAndView("/pages/user/list");
		modelAndView.addObject("userList", userService.getUserList(model));
		return modelAndView;
	}

	@RequestMapping("/detail")
	public ModelAndView detail(User model) {
		if (model == null || model.getId() == null) {
			model.setId(1);
		}
		ModelAndView modelAndView = new ModelAndView("/pages/user/detail");
		modelAndView.addObject("model", userService.getUserById(model.getId()));
		return modelAndView;
	}

}
